package robbie.WeatherApp;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.*;
import android.app.*;
import java.util.*;




public class InformatiiAdapter extends BaseAdapter 
{
	private Activity context;
	ArrayList<Informatie> informatii;
	
	public InformatiiAdapter(Activity unContext)
	{
		this.context = unContext;
		informatii = new ArrayList<Informatie>();
	}

	
	public int getCount() 
	{
		return informatii.size();
	}


	
	public Informatie getItem(int position) 
	{
		return informatii.get(position);
	}

	
	public long getItemId(int arg0) 
	{
		// fiecare element sin lista poate avea un id dar nu e obligatoriu --> vezi daca ii bagi id mai incolo  !!!
		return 0;
	}

	
	public View getView(int position, View view, ViewGroup list)	
	{
		if(view==null)
		{
		LayoutInflater inflater = context.getLayoutInflater();
		view = inflater.inflate(R.layout.information, null);
		}
		
		TextView denumireCampTV = (TextView)view.findViewById(R.id.InformationDenumireCamp);
//		TextView dateCampTV = (TextView)view.findViewById(R.id.InformationDateCamp);
		ImageView iconCampIV = (ImageView)view.findViewById(R.id.InformationIconCamp);
		
		
		
		denumireCampTV.setText(informatii.get(position).toString());
//		dateCampTV.setText(informatii.get(position).dateCamp);
		
		if ( informatii.get(position).iconCamp.equals("/ig/images/weather/chance_of_rain.gif"))
			iconCampIV.setImageResource(R.drawable.chance_of_rain);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/chance_of_snow.gif"))
			iconCampIV.setImageResource(R.drawable.chance_of_snow);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/chance_of_storm.gif"))
			iconCampIV.setImageResource(R.drawable.chance_of_storm);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/chance_of_tstorm.gif"))
			iconCampIV.setImageResource(R.drawable.chance_of_tstorm);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/cloudy.gif"))
			iconCampIV.setImageResource(R.drawable.cloudy);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/dust.gif"))
			iconCampIV.setImageResource(R.drawable.dust);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/flurries.gif"))
			iconCampIV.setImageResource(R.drawable.flurries);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/fog.gif"))
			iconCampIV.setImageResource(R.drawable.fog);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/haze.gif"))
			iconCampIV.setImageResource(R.drawable.haze);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/ic_launcher.gif"))
			iconCampIV.setImageResource(R.drawable.ic_launcher);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/icy.gif"))
			iconCampIV.setImageResource(R.drawable.icy);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/mist.gif"))
			iconCampIV.setImageResource(R.drawable.mist);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/mostly_cloudy.gif"))
			iconCampIV.setImageResource(R.drawable.mostly_cloudy);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/mostly_sunny.gif"))
			iconCampIV.setImageResource(R.drawable.mostly_sunny);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/partly_cloudy.gif"))
			iconCampIV.setImageResource(R.drawable.partly_cloudy);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/rain.gif"))
			iconCampIV.setImageResource(R.drawable.rain);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/sleet.gif"))
			iconCampIV.setImageResource(R.drawable.sleet);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/smoke.gif"))
			iconCampIV.setImageResource(R.drawable.smoke);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/snow.gif"))
			iconCampIV.setImageResource(R.drawable.snow);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/storm.gif"))
			iconCampIV.setImageResource(R.drawable.storm);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/sunny.gif"))
			iconCampIV.setImageResource(R.drawable.sunny);
		else if ( informatii.get(position).iconCamp.equals("/ig/images/weather/thunderstorm.gif"))
			iconCampIV.setImageResource(R.drawable.thunderstorm);
		else if ( informatii.get(position).iconCamp.equals("semnul_exclamarii"))
			iconCampIV.setImageResource(R.drawable.atentie);
		else if ( informatii.get(position).iconCamp.equals("no_icon"))
			iconCampIV.setImageResource(R.drawable.pct);

		return view;
	}
	
	public void adaugaInformatie(String denumireCamp, String dateCamp, String iconCamp)		// si mai urmeaza si alte campuir; executat in AddActivity
	{
		Informatie i = new Informatie();
		i.denumireCamp = denumireCamp;
		i.dateCamp = dateCamp;
		i.iconCamp = iconCamp;
		informatii.add(i);
		this.notifyDataSetChanged();
		
	}
	
	public void stergeInformatie(Informatie i)
	{
		informatii.remove(i);
		this.notifyDataSetChanged();
		
	}
	
}
